




//
//  MyContactVC.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/1.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "MyContactVC.h"
#import "MyContactDemandTabVC.h"
#import "MyContactServiceTabVC.h"
#import "ServiceEvaluationTabVC.h"
#import "ServiceModel.h"
#import "DemandTheHallContentVC.h"
#import "RelationModel.h"
#import "HomeModel.h"
#import "ServiceContentTabVC.h"
@interface MyContactVC ()<UIScrollViewDelegate>
@property(nonatomic,strong) MyContactDemandTabVC *demandVC;
@property(nonatomic,strong) MyContactServiceTabVC *serviceTVC;
@property(nonatomic,strong) MCButton *mcBtn;
@property(nonatomic,strong) MCButton *preMCBtn;
@property(nonatomic,strong) UIScrollView *scrollView;
@end

@implementation MyContactVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我联系的";
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    CGFloat w = kVWidth/2;
    NSArray *titles = @[@"需求",@"服务"];
    for (int i = 0; i < 2; i++) {
        self.mcBtn = [[MCButton alloc]initWithFrame:CGRectMake(w*i, 0, w, 40)];
        [self.view addSubview:self.mcBtn];
        [self.mcBtn setTitle:titles[i] forState:UIControlStateNormal];
        self.mcBtn.tag = i;
        if (i == 0) {
            [self.mcBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
            [self.mcBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
        }else{
            [self.mcBtn setImage:[UIImage new] forState:UIControlStateNormal];
            [self.mcBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
        }
        self.mcBtn.buttonStyle = imageNormalBottom;
        self.mcBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.mcBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        self.mcBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.mcBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
    }
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.mcBtn.frame)+20, kVWidth, kVHeight-self.mcBtn.frame.size.height-self.navigationController.navigationBar.frame.size.height-[[UIApplication sharedApplication] statusBarFrame].size.height-20)];
    self.scrollView.delegate = self;
    self.scrollView.contentSize = CGSizeMake(titles.count*kUIScreen.size.width, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.backgroundColor = kBg;
    [self.view addSubview:self.scrollView];
    __weak typeof (self)weakSelf = self;
    self.demandVC = [[MyContactDemandTabVC alloc]init];
    self.demandVC.returnValueBlock = ^(HomeModel * _Nonnull homeMode) {
        DemandTheHallContentVC *vc = [[DemandTheHallContentVC alloc]init];
        vc.homeModel = homeMode;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    self.demandVC.view.frame = CGRectMake(0, 0, kUIScreen.size.width, self.scrollView.frame.size.height);
    [self.scrollView addSubview:self.demandVC.view];
    self.serviceTVC = [[MyContactServiceTabVC alloc]init];
    self.serviceTVC.returnValueBlock = ^(ServiceModel * _Nonnull model, NSInteger row) {
        if (row == 0) {
            ServiceContentTabVC *vc = [[ServiceContentTabVC alloc]init];
            vc.model = model;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }else {
            //写评
            ServiceEvaluationTabVC *vc = [[ServiceEvaluationTabVC alloc]init];
            vc.returnValueBlock = ^(NSInteger selected) {
                model.evaluateStatus = 1;
                [weakSelf.serviceTVC reloadInternetRowData:selected];
            };
            vc.model = model;
            vc.row = row;
            [weakSelf.navigationController pushViewController:vc animated:YES];
            
        }
        
    };
    self.serviceTVC.view.frame = CGRectMake(kVWidth, 0, kUIScreen.size.width, self.scrollView.frame.size.height);
    [self.scrollView addSubview:self.serviceTVC.view];

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger index = scrollView.contentOffset.x/kVWidth;
    for (id obj in self.view.subviews) {
        
        if ([obj isKindOfClass:[MCButton class]]) {
            MCButton *btn = (MCButton *)obj;
            if (btn.tag == index) {
                XLog(@"btn:%@",btn);
                [btn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
                [btn setTitleColor:kLabel16Color forState:UIControlStateNormal];
            }else{
                [btn setImage:[UIImage new] forState:UIControlStateNormal];
                [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
            }
        }
        
    }
    
}
-(void)clickBtn:(MCButton *)clickBtn
{
    [self.preMCBtn setImage:[UIImage new] forState:UIControlStateNormal];
    [self.preMCBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
    self.scrollView.contentOffset = CGPointMake(clickBtn.tag*kVWidth, 9);
    [clickBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
    [clickBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
    self.preMCBtn = clickBtn;
}


@end

